package com.ruoyi.web.controller.data;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskExecutionRecord;
import com.ruoyi.system.service.ITaskExecutionRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采集任务执行记录信息Controller
 *
 * @author ruoyi
 * @date 2025-04-30
 */
@Controller
@RequestMapping("/system/record")
public class TaskExecutionRecordController extends BaseController
{
    private String prefix = "system/record";

    @Autowired
    private ITaskExecutionRecordService taskExecutionRecordService;

    @RequiresPermissions("system:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询采集任务执行记录信息列表
     */
    @RequiresPermissions("system:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskExecutionRecord taskExecutionRecord)
    {
        startPage();
        List<TaskExecutionRecord> list = taskExecutionRecordService.selectTaskExecutionRecordList(taskExecutionRecord);
        return getDataTable(list);
    }

    /**
     * 导出采集任务执行记录信息列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "采集任务执行记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskExecutionRecord taskExecutionRecord)
    {
        List<TaskExecutionRecord> list = taskExecutionRecordService.selectTaskExecutionRecordList(taskExecutionRecord);
        ExcelUtil<TaskExecutionRecord> util = new ExcelUtil<TaskExecutionRecord>(TaskExecutionRecord.class);
        return util.exportExcel(list, "采集任务执行记录信息数据");
    }

    /**
     * 新增采集任务执行记录信息
     */
    @RequiresPermissions("system:record:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采集任务执行记录信息
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "采集任务执行记录信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskExecutionRecord taskExecutionRecord)
    {
        return toAjax(taskExecutionRecordService.insertTaskExecutionRecord(taskExecutionRecord));
    }

    /**
     * 修改采集任务执行记录信息
     */
    @RequiresPermissions("system:record:edit")
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        TaskExecutionRecord taskExecutionRecord = taskExecutionRecordService.selectTaskExecutionRecordByRecordId(recordId);
        mmap.put("taskExecutionRecord", taskExecutionRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存采集任务执行记录信息
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "采集任务执行记录信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskExecutionRecord taskExecutionRecord)
    {
        return toAjax(taskExecutionRecordService.updateTaskExecutionRecord(taskExecutionRecord));
    }

    /**
     * 删除采集任务执行记录信息
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "采集任务执行记录信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(taskExecutionRecordService.deleteTaskExecutionRecordByRecordIds(ids));
    }
}
